﻿CREATE PROCEDURE [maint].[HelpConfig]
@DbName [sysname]=NULL
AS
BEGIN
	SELECT 
		[ServerName]
		,[DbName]
		,[BackupSets]
		,[BackupAgent]
		,(CASE WHEN (([FullBackupSchedule] &   1) <> 0) THEN 'Mo' ELSE '' END)
		+ (CASE WHEN (([FullBackupSchedule] &  2) <> 0) THEN 'Tu' ELSE '' END)
		+ (CASE WHEN (([FullBackupSchedule] &  4) <> 0) THEN 'We' ELSE '' END)
		+ (CASE WHEN (([FullBackupSchedule] &  8) <> 0) THEN 'Th' ELSE '' END)
		+ (CASE WHEN (([FullBackupSchedule] & 16) <> 0) THEN 'Fr' ELSE '' END)
		+ (CASE WHEN (([FullBackupSchedule] & 32) <> 0) THEN 'Sa' ELSE '' END)
		+ (CASE WHEN (([FullBackupSchedule] & 64) <> 0) THEN 'Su' ELSE '' END)
		+ ' @' + CONVERT(char(8),util.ChangeDateTime('', [FullBackupTime]),108) AS [FULL Backup]
		,(CASE WHEN (([DiffBackupSchedule] &   1) <> 0) THEN 'Mo' ELSE '' END)
		+ (CASE WHEN (([DiffBackupSchedule] &  2) <> 0) THEN 'Tu' ELSE '' END)
		+ (CASE WHEN (([DiffBackupSchedule] &  4) <> 0) THEN 'We' ELSE '' END)
		+ (CASE WHEN (([DiffBackupSchedule] &  8) <> 0) THEN 'Th' ELSE '' END)
		+ (CASE WHEN (([DiffBackupSchedule] & 16) <> 0) THEN 'Fr' ELSE '' END)
		+ (CASE WHEN (([DiffBackupSchedule] & 32) <> 0) THEN 'Sa' ELSE '' END)
		+ (CASE WHEN (([DiffBackupSchedule] & 64) <> 0) THEN 'Su' ELSE '' END)
		+ ' @' + CONVERT(char(8),util.ChangeDateTime('', [DiffBackupTime]),108)
		+ ' every ' + CAST([DiffBackupFrequency] AS varchar) + 'hrs' AS [DIFF Backup]
		,[DefragThreshold]
		,(CASE WHEN (([DefragWeekSchedule] &   1) <> 0) THEN 'Mo' ELSE '' END)
		+ (CASE WHEN (([DefragWeekSchedule] &  2) <> 0) THEN 'Tu' ELSE '' END)
		+ (CASE WHEN (([DefragWeekSchedule] &  4) <> 0) THEN 'We' ELSE '' END)
		+ (CASE WHEN (([DefragWeekSchedule] &  8) <> 0) THEN 'Th' ELSE '' END)
		+ (CASE WHEN (([DefragWeekSchedule] & 16) <> 0) THEN 'Fr' ELSE '' END)
		+ (CASE WHEN (([DefragWeekSchedule] & 32) <> 0) THEN 'Sa' ELSE '' END)
		+ (CASE WHEN (([DefragWeekSchedule] & 64) <> 0) THEN 'Su' ELSE '' END)
		+ ' @ '
		+ (CASE WHEN (([DefragDaySchedule] &        1) <> 0) THEN '1,' ELSE '' END)
		+ (CASE WHEN (([DefragDaySchedule] &        2) <> 0) THEN '2,' ELSE '' END)
		+ (CASE WHEN (([DefragDaySchedule] &        4) <> 0) THEN '3,' ELSE '' END)
		+ (CASE WHEN (([DefragDaySchedule] &        8) <> 0) THEN '4,' ELSE '' END)
		+ (CASE WHEN (([DefragDaySchedule] &       16) <> 0) THEN '5,' ELSE '' END)
		+ (CASE WHEN (([DefragDaySchedule] &       32) <> 0) THEN '6,' ELSE '' END)
		+ (CASE WHEN (([DefragDaySchedule] &       64) <> 0) THEN '7,' ELSE '' END)
		+ (CASE WHEN (([DefragDaySchedule] &      128) <> 0) THEN '8,' ELSE '' END)
		+ (CASE WHEN (([DefragDaySchedule] &      256) <> 0) THEN '9,' ELSE '' END)
		+ (CASE WHEN (([DefragDaySchedule] &      512) <> 0) THEN '10,' ELSE '' END)
		+ (CASE WHEN (([DefragDaySchedule] &     1024) <> 0) THEN '11,' ELSE '' END)
		+ (CASE WHEN (([DefragDaySchedule] &     2048) <> 0) THEN '12,' ELSE '' END)
		+ (CASE WHEN (([DefragDaySchedule] &     4096) <> 0) THEN '13,' ELSE '' END)
		+ (CASE WHEN (([DefragDaySchedule] &     8192) <> 0) THEN '14,' ELSE '' END)
		+ (CASE WHEN (([DefragDaySchedule] &    16384) <> 0) THEN '15,' ELSE '' END)
		+ (CASE WHEN (([DefragDaySchedule] &    32768) <> 0) THEN '16,' ELSE '' END)
		+ (CASE WHEN (([DefragDaySchedule] &    65536) <> 0) THEN '17,' ELSE '' END)
		+ (CASE WHEN (([DefragDaySchedule] &   131072) <> 0) THEN '18,' ELSE '' END)
		+ (CASE WHEN (([DefragDaySchedule] &   262144) <> 0) THEN '19,' ELSE '' END)
		+ (CASE WHEN (([DefragDaySchedule] &   524288) <> 0) THEN '20,' ELSE '' END)
		+ (CASE WHEN (([DefragDaySchedule] &  1048576) <> 0) THEN '21,' ELSE '' END)
		+ (CASE WHEN (([DefragDaySchedule] &  2097152) <> 0) THEN '22,' ELSE '' END)
		+ (CASE WHEN (([DefragDaySchedule] &  4194304) <> 0) THEN '23,' ELSE '' END)
		+ (CASE WHEN (([DefragDaySchedule] &  8388608) <> 0) THEN '24' ELSE '' END)
		 AS [Defrag Schedule]
		,(CASE WHEN (([CheckDbWeekSchedule] &   1) <> 0) THEN 'Mo' ELSE '' END)
		+ (CASE WHEN (([CheckDbWeekSchedule] &  2) <> 0) THEN 'Tu' ELSE '' END)
		+ (CASE WHEN (([CheckDbWeekSchedule] &  4) <> 0) THEN 'We' ELSE '' END)
		+ (CASE WHEN (([CheckDbWeekSchedule] &  8) <> 0) THEN 'Th' ELSE '' END)
		+ (CASE WHEN (([CheckDbWeekSchedule] & 16) <> 0) THEN 'Fr' ELSE '' END)
		+ (CASE WHEN (([CheckDbWeekSchedule] & 32) <> 0) THEN 'Sa' ELSE '' END)
		+ (CASE WHEN (([CheckDbWeekSchedule] & 64) <> 0) THEN 'Su' ELSE '' END)
		+ ' @ '
		+ (CASE WHEN (([CheckDbDaySchedule] &        1) <> 0) THEN '1,' ELSE '' END)
		+ (CASE WHEN (([CheckDbDaySchedule] &        2) <> 0) THEN '2,' ELSE '' END)
		+ (CASE WHEN (([CheckDbDaySchedule] &        4) <> 0) THEN '3,' ELSE '' END)
		+ (CASE WHEN (([CheckDbDaySchedule] &        8) <> 0) THEN '4,' ELSE '' END)
		+ (CASE WHEN (([CheckDbDaySchedule] &       16) <> 0) THEN '5,' ELSE '' END)
		+ (CASE WHEN (([CheckDbDaySchedule] &       32) <> 0) THEN '6,' ELSE '' END)
		+ (CASE WHEN (([CheckDbDaySchedule] &       64) <> 0) THEN '7,' ELSE '' END)
		+ (CASE WHEN (([CheckDbDaySchedule] &      128) <> 0) THEN '8,' ELSE '' END)
		+ (CASE WHEN (([CheckDbDaySchedule] &      256) <> 0) THEN '9,' ELSE '' END)
		+ (CASE WHEN (([CheckDbDaySchedule] &      512) <> 0) THEN '10,' ELSE '' END)
		+ (CASE WHEN (([CheckDbDaySchedule] &     1024) <> 0) THEN '11,' ELSE '' END)
		+ (CASE WHEN (([CheckDbDaySchedule] &     2048) <> 0) THEN '12,' ELSE '' END)
		+ (CASE WHEN (([CheckDbDaySchedule] &     4096) <> 0) THEN '13,' ELSE '' END)
		+ (CASE WHEN (([CheckDbDaySchedule] &     8192) <> 0) THEN '14,' ELSE '' END)
		+ (CASE WHEN (([CheckDbDaySchedule] &    16384) <> 0) THEN '15,' ELSE '' END)
		+ (CASE WHEN (([CheckDbDaySchedule] &    32768) <> 0) THEN '16,' ELSE '' END)
		+ (CASE WHEN (([CheckDbDaySchedule] &    65536) <> 0) THEN '17,' ELSE '' END)
		+ (CASE WHEN (([CheckDbDaySchedule] &   131072) <> 0) THEN '18,' ELSE '' END)
		+ (CASE WHEN (([CheckDbDaySchedule] &   262144) <> 0) THEN '19,' ELSE '' END)
		+ (CASE WHEN (([CheckDbDaySchedule] &   524288) <> 0) THEN '20,' ELSE '' END)
		+ (CASE WHEN (([CheckDbDaySchedule] &  1048576) <> 0) THEN '21,' ELSE '' END)
		+ (CASE WHEN (([CheckDbDaySchedule] &  2097152) <> 0) THEN '22,' ELSE '' END)
		+ (CASE WHEN (([CheckDbDaySchedule] &  4194304) <> 0) THEN '23,' ELSE '' END)
		+ (CASE WHEN (([CheckDbDaySchedule] &  8388608) <> 0) THEN '24' ELSE '' END)
		 AS [Check Db Schedule]
	FROM [config].[DbMaintenance]
	WHERE ([DbName] = ISNULL(@DbName,[DbName]))
END